﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;

namespace Mengoo.BDMTier
{
    /// <summary>
    /// 
    /// </summary>
    public abstract class Service
    {
        public DAO dao;

        #region 基础方法 执行简单SQL

        #region Insert
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="model">记录实体</param>
        /// <returns></returns>
        public virtual int Add(object model)
        {
            return dao.Add(model);
        }

        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="model">记录实体</param>
        /// <param name="exceptColumns">不需要插入的列，用，分隔</param>
        /// <returns></returns>
        public virtual int Add(object model, string exceptColumns)
        {
            return dao.Add(model, exceptColumns);
        }

        /// <summary>
        /// 添加多条记录
        /// </summary>
        /// <param name="modelList">记录集合</param>
        /// <returns></returns>
        public virtual int Add(List<object> modelList)
        {
            return dao.Add(modelList);
        }

        /// <summary>
        /// 添加多条记录
        /// </summary>
        /// <param name="modelList">记录集合</param>
        /// <param name="exceptColumns">不需要插入的列，用，分隔</param>
        /// <returns></returns>
        public virtual int Add(List<object> modelList, string exceptColumns)
        {
            return dao.Add(modelList, exceptColumns);
        }

        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="columns">列的键值对</param>
        /// <returns></returns>
        public virtual int Add(Hashtable columns)
        {
            return dao.Add(columns);
        }

        /// <summary>
        /// 添加多条记录
        /// </summary>
        /// <param name="columnsList">列的键值对</param>
        /// <returns></returns>
        public virtual int Add(List<Hashtable> columnsList)
        {
            return dao.Add(columnsList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// 删除记录，根据条件
        /// </summary>
        /// <param name="where">删除条件</param>
        /// <returns></returns>
        public virtual int Del(string where)
        {
            return dao.Del(where);
        }

        /// <summary>
        /// 删除记录，根据记录实体
        /// </summary>
        /// <param name="model">记录实体</param>
        /// <returns></returns>
        public virtual int Del(object model)
        {
            return dao.Del(model);
        }

        /// <summary>
        /// 删除记录，根据记录实体
        /// </summary>
        /// <param name="model">记录实体</param>
        /// <param name="keyField">关键字段名称</param>
        /// <returns></returns>
        public virtual int Del(object model, string keyField)
        {
            return dao.Del(model, keyField);
        }

        /// <summary>
        /// 删除记录集合
        /// </summary>
        /// <param name="modelList">要删除的实体记录集合</param>
        /// <returns></returns>
        public virtual int Del(List<object> modelList)
        {
            return dao.Del(modelList);
        }

        /// <summary>
        /// 删除记录集合
        /// </summary>
        /// <param name="modelList">要删除的实体记录集合</param>
        /// <param name="keyField">记录的关键字段名称</param>
        /// <returns></returns>
        public virtual int Del(List<object> modelList, string keyField)
        {
            return dao.Del(modelList, keyField);
        }
        #endregion

        #region Update
        /// <summary>
        /// 更新记录，根据实体和默认的关键字段名称
        /// </summary>
        /// <param name="model">数据实体</param>
        /// <returns></returns>
        public virtual int Update(object model)
        {
            return dao.Update(model);
        }

        /// <summary>
        /// 更新记录，根据实体和关键字段名称
        /// </summary>
        /// <param name="model">数据实体</param>
        /// <param name="keyField">关键字字段</param>
        /// <returns></returns>
        public virtual int Update(object model, string keyField)
        {
            return dao.Update(model, keyField);
        }

        /// <summary>
        /// 更新记录，根据列的键值对
        /// </summary>
        /// <param name="columns">列的键值对</param>
        /// <param name="where">更新条件</param>
        /// <returns></returns>
        public virtual int Update(Hashtable columns, string where)
        {
            return dao.Update(columns, where);
        }
        #endregion

        #region Select
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <returns></returns>
        public virtual DataTable GetTableList()
        {
            return dao.GetTableList();
        }

        /// <summary>
        /// 获取列表，根据查询条件
        /// </summary>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public virtual DataTable GetTableList(string where)
        {
            return dao.GetTableList(where);
        }
        /// <summary>
        /// 获取列表，根据查询条件，指定表名
        /// </summary>
        /// <param name="columns">要查询的列</param>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public virtual DataTable GetTableList(string columns, string where)
        {
            return dao.GetTableList(columns, where);
        }
        #endregion

        #region GetModel
        /// <summary>
        /// 获取Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public T GetModel<T>(string keyValue)
        {
            return dao.GetModel<T>(keyValue);
        }


        /// <summary>
        /// 获取Model
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="keyValue"></param>
        /// <returns></returns>
        public T GetModel<T>(string where, string columns)
        {
            return dao.GetModel<T>(where, columns);
        }


        /// <summary>
        /// 获取ModelList
        /// </summary>
        /// <typeparam name="T">要获取的对象类型</typeparam>
        /// <param name="where">查询条件</param>
        /// <returns></returns>
        public List<T> GetModelList<T>(string where)
        {
            return dao.GetModelList<T>(where);
        }

        /// <summary>
        /// 获取ModelList
        /// </summary>
        /// <typeparam name="T">要获取的对象类型</typeparam>
        /// <param name="where">查询条件</param>
        /// <param name="columns">要查询的列</param>
        /// <returns></returns>
        public List<T> GetModelList<T>(string where, string columns)
        {
            return dao.GetModelList<T>(where, columns);
        }
        #endregion

        #endregion



        #region 基础方法，执行存储过程
        public int AddByStoreProcess(object model)
        {
            return dao.AddByStoreProcess(model);
        }

        public int DelByStoreProcess()
        {
            return dao.DelByStoreProcess();
        }

        public int UpdateByStoreProcess()
        {
            return dao.UpdateByStoreProcess();
        }

        public DataTable GetTableListByStoreProcess()
        {
            return dao.GetTableListByStoreProcess();
        }
        #endregion
    }
}
